package com.cj.mainmodule.viewmodel

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope
import com.cj.mainmodule.repo.RepoManager
import com.cj.mainmodule.repo.observable.SchedulerTransformer
import kotlinx.coroutines.launch

/**
 *created by chen jun
 *on 2021/5/24 18:26
 */
class MainViewModel:ViewModel() {

    fun getChapters(){
        val disposable = RepoManager.getChapters()
            .compose(SchedulerTransformer())
            .subscribe(
                {
                    Log.e("junchen", "getChapters: $it  ${Thread.currentThread().name}")
                },
                {
                    Log.e("junchen", "getChapters:$it  ${Thread.currentThread().name}")
                },
                {

                }
            )
    }
    fun getChapters1(){
       viewModelScope.launch {
           Log.d("junchen", "getChapters1: ${Thread.currentThread().name}")
               val ret = RepoManager.getChapters1()
       }
    }
    val a = liveData{
        val ret = RepoManager.getChapters1()
        emit(ret)
    }
}